package com.english_test_sys.controller;

import com.english_test_sys.service.RankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/ranking")
public class RankingController {

    @Autowired
    private RankingService rankingService;

    @GetMapping
    public ResponseEntity<?> getRanking(
            @RequestParam(defaultValue = "all") String type
    ) {
        try {
            Map<String, Object> data = rankingService.getRankingData(type);

            return ResponseEntity.ok()
                    .body(Map.of(
                            "success", true,
                            "message", "获取排行榜成功",
                            "data", data
                    ));

        } catch (Exception e) {
            return ResponseEntity.status(500)
                    .body(Map.of(
                            "success", false,
                            "message", "获取排行榜失败: " + e.getMessage()
                    ));
        }
    }
    @GetMapping("/wrong_questions")
    public String wrong_questions() {
        return "wrong_questions";
    }
}